﻿using System;
using GCT.Foundation.Workers;
using L._52Abp;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace GCT.Foundation
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var options = new MigratorOptions(args);

            // 运行迁移
            {
                var startup = new Startup(options);
                L52AbpBootstrapper.Run<FoundationTemplateMigratorModule>(startup);
            }

            // 监听
            if (options.Listener)
            {
                Console.WriteLine("启用监听");
                CreateHostBuilder(new string[] { }).Build().Run();
                Console.WriteLine("停止监听");
            }

            // 退出拦截
            if (options.QuietMode)
            {
                Console.WriteLine("自动退出...");
            }
            else
            {
                Console.WriteLine("按下回车键退出...");
                Console.ReadLine();
            }



        }

        /// <summary>
        /// Host 主机
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureServices((hostContext, services) =>
                {
                    services.AddHostedService<MigratorListenerWorker>();
                });
    }
}
